﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SoftFX.Extended;

namespace Mql2Fdk
{
	internal class FixConnectionStrings : ConnectionStrings
	{
		public FixConnectionStrings(string address, string username, string password, string logLocation)
		{
			base.FeedConnectionString = CreateFeedConnectionString(address, username, password, logLocation);
			base.TradeConnectionString = CreateTradeConnectionString(address, username, password, logLocation);
		}
		private static string CreateFeedConnectionString(string address, string username, string password, string logLocation)
		{
			FixConnectionStringBuilder builder = new FixConnectionStringBuilder();
			builder.TargetCompId = "EXECUTOR";
			builder.ProtocolVersion = FixProtocolVersion.TheLatestVersion.ToString();
			builder.TradingPlatformAddress = address;
			builder.Username = username;
			builder.Password = password;
			builder.SecureConnection = true;
			builder.TradingPlatformPort = 5003;
			builder.ExcludeMessagesFromLogs = "W";
			builder.FixLogDirectory = logLocation;

			builder.DecodeLogFixMessages = true;

			string result = builder.ToString();
			return result;
		}
		private static string CreateTradeConnectionString(string address, string username, string password, string logsLocation)
		{
			FixConnectionStringBuilder builder = new FixConnectionStringBuilder();
			builder.TargetCompId = "EXECUTOR";
			builder.ProtocolVersion = FixProtocolVersion.TheLatestVersion.ToString();
			builder.TradingPlatformAddress = address;
			builder.Username = username;
			builder.Password = password;
			builder.SecureConnection = true;
			builder.TradingPlatformPort = 5004;

			builder.DecodeLogFixMessages = true;

			builder.FixLogDirectory = logsLocation;

			string result = builder.ToString();
			return result;
		}
	}
}
